package com.chuangjiangx.member.basic.ddd.domain.model;

import com.chuangjiangx.domain.shared.model.PayTerminal;

/**
 * 来源终端
 *
 * @author LeeXyan
 * @Date 2018/1/26 16:30
 **/
public enum MbrSourceTerminal {
    MERCHANT_APP("商户APP", (byte) 1),
    CASHIER_API_TERMINAL("收银台", (byte) 2),
    APPLET_TERMINAL("小程序", (byte) 3),
    H5_TERMINAL("H5", (byte) 4),
    MERCHANT_WEB("商户web平台", (byte) 5);


    public final String name;
    public final Byte value;

    MbrSourceTerminal(String name, byte value) {
        this.name = name;
        this.value = value;
    }

    public static MbrSourceTerminal getSourceTerminal(byte value) {
        for (MbrSourceTerminal mbrSourceTerminal : MbrSourceTerminal.values()) {
            if (mbrSourceTerminal.value == value) {
                return mbrSourceTerminal;
            }
        }
        return null;
    }

    public static MbrSourceTerminal fromSourceTerminal(byte value) {
        if (value == PayTerminal.PC.code) {
            return CASHIER_API_TERMINAL;
        } else if (value == PayTerminal.ANDROID.code) {
            return MERCHANT_APP;
        } else if (value == PayTerminal.IOS.code) {
            return MERCHANT_APP;
        } else if (value == PayTerminal.CASHIER_API.code) {
            return CASHIER_API_TERMINAL;
        } else if (value == PayTerminal.QR_CODE.code) {
            return H5_TERMINAL;
        } else if (value == PayTerminal.LKL.code) {
            return MERCHANT_APP;
        } else if (value == PayTerminal.MINI_APPS.code) {
            return APPLET_TERMINAL;
        } else {
            return H5_TERMINAL;
        }
    }
}
